package org.zpmis.domain.invoice.vo;

import lombok.Data;
import org.zpmis.domain.invoice.model.Invoice;

import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class InvoiceListVo implements Serializable {

    private Long id;

    /**
     * 开票业务id，可以是订单id  合同id  账单id 等
     */
    private Long businessId;

    /**
     * 开票业务类型，1订单 2合同 3账单 可以是订单 合同 账单 等
     */
    private Integer businessType;

    /**
     * 开票金额
     */
    private String invoiceAmount;

    /**
     * 发票类型 1纸质 2电子
     */
    private Integer invoiceType;

    /**
     * 物流单号
     */
    private String logisticsNum;

    /**
     * 开票类型 1增值税专用发票 2增值税普通发票
     */
    private Integer openInvoiceType;

    /**
     * 开票企业名称
     */
    private String invoiceCompanyName;

    /**
     * 纳税人识别号
     */
    private String invoiceTaxpayerIdentiNumber;

    /**
     * 开户银行
     */
    private String bankName;

    /**
     * 开户名
     */
    private String bankAccountName;

    /**
     * 开户账号
     */
    private String bankAccount;

    /**
     * 开票地址
     */
    private String invoiceAddress;

    /**
     * 开票电话
     */
    private String invoiceMobile;

    /**
     * 发票附件地址
     */
    private String invoiceAttachment;

    /**
     * 发票附件名称
     */
    private String attachmentName;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 审核开票时间
     */
    private String auditTime;

    /**
     * 开票状态 0 待审核 1 已完成 2 已拒绝
     */
    private Integer status;

    /**
     * 审核备注
     */
    private String remark;

    /**
     * 收货人
     */
    private String consignee;
    /**
     * 收货地址
     */
    private String deliveryAdress;
    /**
     * 收货人电话
     */
    private String deliveryMobile;
    /**
     * 邮箱
     */
    private String email;

    public InvoiceListVo(Invoice invoice) {
        this.id = invoice.getId();
        this.businessId = invoice.getBusinessId();
        this.businessType = invoice.getBusinessType();
        this.invoiceAmount = invoice.getInvoiceAmount() == null ? "0" : invoice.getInvoiceAmount().toString();
        this.invoiceType = invoice.getInvoiceType();
        this.logisticsNum = invoice.getLogisticsNum();
        this.openInvoiceType = invoice.getOpenInvoiceType();
        this.invoiceCompanyName = invoice.getInvoiceCompanyName();
        this.invoiceTaxpayerIdentiNumber = invoice.getInvoiceTaxpayerIdentiNumber();
        this.bankName = invoice.getBankName();
        this.bankAccountName = invoice.getBankAccountName();
        this.bankAccount = invoice.getBankAccount();
        this.invoiceAddress = invoice.getInvoiceAddress();
        this.invoiceMobile = invoice.getInvoiceMobile();
        this.invoiceAttachment = invoice.getInvoiceAttachment();
        this.attachmentName = invoice.getAttachmentName();
        this.createId = invoice.getCreateId();
        this.createPerson = invoice.getCreatePerson();
        this.createTime = invoice.getCreateTime() == null ? "" :  LocalDateTime.ofInstant(Instant.ofEpochMilli(invoice.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.auditTime = invoice.getAuditTime() == null ? "" :  LocalDateTime.ofInstant(Instant.ofEpochMilli(invoice.getAuditTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));;
        this.status = invoice.getStatus();
        this.remark = invoice.getRemark();
        this.consignee = invoice.getConsignee();
        this.deliveryAdress = invoice.getDeliveryAdress();
        this.deliveryMobile = invoice.getDeliveryMobile();
        this.email = invoice.getEmail();
    }
}